<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                xmlns:comp="http://java.sun.com/jsf/composite/comp"
                template="./template.xhtml">

    <ui:define name="content">
        <h:form id="form">
            <p:dialog id="uploadFile" header="Upload File" widgetVar="uploadFileDlg" height="150" width="550">

                <p:fileUpload  mode="advanced" fileUploadListener="#{filesTableBean.handleFileUpload}" update=":form"/>  

            </p:dialog>

            <p:dialog id="createFolder" header="Create folder" widgetVar="createFolderDlg" height="100">
                <h:outputLabel for="folderName" value="Name"/>
                <p:inputText id="folderName" value="#{filesTableBean.newFolderName}"/>
                <p:commandButton action="#{filesTableBean.createNewFolder()}" value="Create" update=":form"/> 
            </p:dialog>

            <p:dialog id="modalDialog" header="File download" widgetVar="downloadDlg" height="100">  
                <h:outputLabel value="Download file: "/>
                <p:commandLink ajax="false" id="downloadLink" value="#{filesTableBean.selectedItem.name}">  
                    <p:fileDownload value="#{filesTableBean.fileDownload()}" />
                </p:commandLink>
            </p:dialog>

            <p:growl id="messages" showDetail="true"/>  

            <p:panel id="panel" style="width: 800px">


                <p:menubar>
                    <p:menuitem value="Up" icon="ui-icon-circle-arrow-w" action="#{filesTableBean.upFolder()}" update=":form" disabled="#{!filesTableBean.upMetod}"/>
                    <p:menuitem value="Open" icon="ui-icon-circle-arrow-n" action="#{filesTableBean.openFolder()}" update=":form" disabled="#{!filesTableBean.selectedItem.folder}"/>

                    <p:menuitem value="Delete" icon="ui-icon-trash" disabled="#{!filesTableBean.deletePermit}" update=":form"/>
                    <p:menuitem id="downloadButton" value="Download" disabled="#{!filesTableBean.selectedRow}" oncomplete="downloadDlg.show();" icon="ui-icon-disk" style="float: right">
                        <p:fileDownload value="#{filesTableBean.fileDownload()}" />
                    </p:menuitem>
                    <p:menuitem value="Share" icon="ui-icon-transferthick-e-w" disabled="#{!filesTableBean.sharingPermit}" action="#{filesTableBean.shareFile()}"/>
                    <p:menuitem value="Create folder" icon="ui-icon-folder-collapsed" disabled="#{!filesTableBean.uploadFolderCreatePermit}" oncomplete="createFolderDlg.show();"/>
                    <p:menuitem value="Upload file" icon="ui-icon-contact" disabled="#{!filesTableBean.uploadFolderCreatePermit}" oncomplete="uploadFileDlg.show();"/>

                </p:menubar> 

                <p:dataTable id="Files" var="file" value="#{filesTableBean.fileList}" rowKey="#{file.name}" selection="#{filesTableBean.selectedItem}" selectionMode="single">  

                    <p:ajax event="rowSelect" update=":form" oncomplete="#{filesTableBean.onRowSelect()}" />   

                    <p:column headerText="Name"> 
                        #{file.name}
                    </p:column>  

                    <p:column headerText="Type">  
                        #{file.type}
                    </p:column>  

                    <p:column headerText="Owner">
                        #{file.owner}
                    </p:column>

                    <p:column headerText="Rights">
                        #{file.rigtsString}
                    </p:column>

                    <p:column headerText="Last change" >
                        #{file.lastChange}
                    </p:column>  

                    <p:column headerText="Size">  
                        #{file.size}
                    </p:column>  

                    <f:facet name="footer">  

                    </f:facet>  

                </p:dataTable>



            </p:panel>
        </h:form>
    </ui:define>

</ui:composition>
